package com.yxx.community.controller;

import com.yxx.community.dto.PaginationDTO;
import com.yxx.community.mapper.QuestionMapper;
import com.yxx.community.model.QuestionExample;
import com.yxx.community.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Author: YuXinXin
 * @Description:
 * @Date:Created in 14:39 2020/1/25
 **/
@Controller
public class IndexController {

  @Autowired
  private QuestionService questionService;
  @Autowired
  private QuestionMapper questionMapper;

  @GetMapping("/")
  public String index(Model model,
                      @RequestParam(name = "page",defaultValue = "1")Integer page,
                      @RequestParam(name = "size",defaultValue = "5")Integer size,
                      @RequestParam(name = "search",required = false)String search){
    PaginationDTO pagination = questionService.list(search,page, size);
    model.addAttribute("pagination",pagination);
    model.addAttribute("search",search);
    return "index";
  }
}
